const statusValue = [
    { label: '已删除', value: -3 },
    { label: '已取消', value: -2 },
    { label: '已过期', value: -1 },
    { label: '未支付', value: 1 },
    { label: '待发货', value: 2 },
    { label: '待收货', value: 3 },
    { label: '已收货', value: 4 },
    { label: '已完成', value: 5 },
    { label: '退款中', value: 6 },
    { label: '已退款', value: 7 },
    { label: '审核未通过', value: 9 },
    { label: '待审核', value: 11 }
]
export const usePublic = () => {
    //登录
    const toLogin = async () => {
        uni.showToast({
            icon: 'error',
            title: '请先登录!',
            duration: 1000
        })
        setTimeout(() => {
            uni.reLaunch({
                url: '/pages/login/index'
            })
        }, 1000)
    }
    //预览图片
    const toPreview = (item: any, current: string) => {
        uni.previewImage({
            urls: item,
            current: current,
            longPressActions: {
                itemList: ['发送给朋友', '保存图片', '收藏']
            }
        })
    }
    //打开地图
    const openMap = (latitude: number, longitude: number, name: string) => {
        uni.openLocation({
            latitude: Number(latitude),
            longitude: Number(longitude),
            name: name
        })
    }
    //拨打电话
    const callPhone = (phone: string) => {
        const res = uni.getSystemInfoSync()
        // ios系统默认有个模态框
        if (res.platform == 'ios') {
            uni.makePhoneCall({
                phoneNumber: phone
            })
        } else {
            //安卓手机手动设置一个showActionSheet
            uni.showActionSheet({
                itemList: [phone, '呼叫'],
                success: function (res) {
                    if (res.tapIndex == 1) {
                        uni.makePhoneCall({
                            phoneNumber: phone
                        })
                    }
                }
            })
        }
    }
    //订单状态
    const changeStatusText = (status: number) => {
        for (let i = 0; i < statusValue.length; i++) {
            if (statusValue[i].value === status) {
                return statusValue[i].label
            }
        }
        return '' // 如果没有匹配的状态值，默认返回空字符串
    }
    return {
        toLogin,
        // commonScan,
        openMap,
        callPhone,
        toPreview,
        changeStatusText
    }
}
